<?php

namespace app\home\controller;

use app\Controller;

/**
 * 播放接口数据处理类
 * Class Player
 * @package app\home\controller
 */
class Player extends Controller
{

    protected $wd;
    protected $api;

    /**
     * 初始化数据
     * Player constructor.
     * @param string $wd
     * @param $api
     */
    public function __construct($wd = '', $api)
    {
        $this->wd = $wd;
        $this->api = $api;
    }

    /**
     * 尝鲜1接口搜索结果
     * @return array
     */
    public function doSearch0()
    {
        $apiArr = explode('@', $this->api);
        $url = $apiArr[0] . $this->wd;
        $html = $this->curl($url);
        $html = json_decode($html, true);
        $list = [];
        foreach ($html['data'] as $key => $item) {
            $list[$key]['image'] = str_replace('http:','',$item['vod_pic']);
            $list[$key]['name'] = $item['vod_name'];
            $list[$key]['content'] = $item['vod_content'];
            // 正则取出 用于后续兼容多个资源站 api 数据格式
            preg_match_all("/http(.*?)\.m3u8/", $item['vod_url'], $newPlay);
            preg_match_all('/(.*?)\$/', $item['vod_url'], $newName);
            $list[$key]['vod_url'] = $newPlay[0];
            $list[$key]['vod_name'] = $newName[1];
            $list[$key]['continu'] = $item['vod_continu']; // 更新至 22 集
            $list[$key]['id'] = $item['vod_id'];
        }
        return $list;
    }

    /**
     * 尝鲜2接口搜索结果
     * @return array
     */
    public function doSearch1()
    {
        $apiArr = explode('@', $this->api);
        $url = $apiArr[0] . $this->wd;
        $html = $this->curl($url);
        $html = json_decode($html, true);
        $list = [];
        foreach ($html['data'] as $key => $item) {
            $list[$key]['image'] = $item['vod_pic'];
            $list[$key]['name'] = $item['vod_name'];
            $list[$key]['content'] = $item['vod_content'];
            // 正则取出 用于后续兼容多个资源站 api 数据格式
            preg_match_all("/http(.*?)\.m3u8/", $item['vod_url'], $newPlay);
            preg_match_all('/(.*?)\$/', $item['vod_url'], $newName);
            $list[$key]['vod_url'] = $newPlay[0];
            $list[$key]['vod_name'] = $newName[1];
            $list[$key]['continu'] = $item['vod_continu']; // 更新至 22 集
            $list[$key]['id'] = $item['vod_id'];
        }
        return $list;
    }

    /**
     * 尝鲜3接口搜索结果
     * @return array
     */
    public function doSearch2()
    {
        $apiArr = explode('@', $this->api);
        $url = $apiArr[0] . $this->wd;
        $html = $this->curl($url);
        $html = json_decode($html, true);
        $list = [];
        foreach ($html['data'] as $key => $item) {
            $list[$key]['image'] = str_replace('http:','',$item['vod_pic']);
            $list[$key]['name'] = $item['vod_name'];
            $list[$key]['content'] = $item['vod_content'];
            $item['vod_url'] = explode('$$$', $item['vod_url'])[1];
            // 正则取出 用于后续兼容多个资源站 api 数据格式
            preg_match_all("/http(.*?)\.m3u8/", $item['vod_url'], $newPlay);
            preg_match_all('/(.*?)\$/', $item['vod_url'], $newName);
            $list[$key]['vod_url'] = $newPlay[0];
            $list[$key]['vod_name'] = $newName[1];
            $list[$key]['continu'] = $item['vod_continu']; // 更新至 22 集
            $list[$key]['id'] = $item['vod_id'];
        }
        return $list;
    }

    /**
     * 尝鲜4接口搜索结果
     * @return array
     */
    public function doSearch3()
    {
        $apiArr = explode('@', $this->api);
        $url = $apiArr[0] . $this->wd;
        $html = $this->curl($url);
        $html = json_decode($html, true);
        $list = [];
        foreach ($html['data'] as $key => $item) {
            $list[$key]['image'] = str_replace('http:','',$item['vod_pic']);
            $list[$key]['name'] = $item['vod_name'];
            $list[$key]['content'] = $item['vod_content'];
            // 正则取出 用于后续兼容多个资源站 api 数据格式
            preg_match_all("/http(.*?)\.m3u8/", $item['vod_url'], $newPlay);
            preg_match_all('/(.*?)\$/', $item['vod_url'], $newName);
            $list[$key]['vod_url'] = $newPlay[0];
            $list[$key]['vod_name'] = $newName[1];
            $list[$key]['continu'] = $item['vod_continu']; // 更新至 22 集
            $list[$key]['id'] = $item['vod_id'];
        }
        return $list;
    }

    /**
     * 尝鲜 5 号搜索结果
     * @return array
     */
    public function doSearch4()
    {
        $apiArr = explode('@', $this->api);
        $url = $apiArr[0] . $this->wd;
        $html = $this->curl($url);
        $html = json_decode($html, true);
        $list = [];
        foreach ($html['data'] as $key => $item) {
            $list[$key]['image'] = str_replace('http:','',$item['vod_pic']);
            $list[$key]['name'] = $item['vod_name'];
            $list[$key]['content'] = $item['vod_content'];
            $item['vod_url'] = explode('$$$', $item['vod_url'])[0];
            // 正则取出 用于后续兼容多个资源站 api 数据格式
            preg_match_all("/http(.*?)\.m3u8/", $item['vod_url'], $newPlay);
            preg_match_all('/(.*?)\$/', $item['vod_url'], $newName);
            $list[$key]['vod_url'] = $newPlay[0];
            $list[$key]['vod_name'] = $newName[1];
            $list[$key]['continu'] = $item['vod_continu']; // 更新至 22 集
            $list[$key]['id'] = $item['vod_id'];
        }
        return $list;
    }

    /**
     * 尝鲜 6 号搜索结果
     * @return array
     */
    public function doSearch5()
    {
        $apiArr = explode('@', $this->api);
        $url = $apiArr[0] . $this->wd;
        $html = $this->curl($url);
        $html = json_decode($html, true);
        $list = [];
        foreach ($html['data'] as $key => $item) {
            $list[$key]['image'] = str_replace('http:','',$item['vod_pic']);
            $list[$key]['name'] = $item['vod_name'];
            $list[$key]['content'] = $item['vod_content'];
            $item['vod_url'] = explode('$$$', $item['vod_url'])[1];
            // 正则取出 用于后续兼容多个资源站 api 数据格式
            preg_match_all("/http(.*?)\.m3u8/", $item['vod_url'], $newPlay);
            preg_match_all('/(.*?)\$/', $item['vod_url'], $newName);
            $list[$key]['vod_url'] = $newPlay[0];
            $list[$key]['vod_name'] = $newName[1];
            $list[$key]['continu'] = $item['vod_continu']; // 更新至 22 集
            $list[$key]['id'] = $item['vod_id'];
        }
        return $list;
    }

}
